<?php

class User_Model_Users extends Zend_Db_Table_Abstract
{
    protected $_name = 'users';
    protected $_primary = 'mail';
    
    
    public function login($mail, $password)
    {
        $result = $this->find($mail);
        
        if(sizeof($result) == 0) return -1;
        if($password != $result[0]['pass']) return -2;
        
        return 0;
    }
 
    public function crea_compta($mail, $pass, $nom){
        $res = $this->find($mail);
        
        if($res->count()!= 0)   return -1;  // Error: compta existent
        
        $data = array($mail,$pass,$nom);
        
        $data = array(
            'mail' => $mail,
            'pass' => $pass,
            'nom'  => $nom
        );
        $this->insert($data);
        return 0;
    }

}